home *** CD-ROM | disk | FTP | other *** search
- /* Gadgets.c */
-
- /* File contains functions which create and handle interaction with all
- window gadgets */
-
- #include <exec/types.h>
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/intuition_protos.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/GfxBase.h>
- #include <intuition/intuition.h>
- #include <intuition/IntuitionBase.h>
- #include <libraries/gadtools.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- #include "CycleDBase.h"
-
- /*
- ** Function to handle a GADGETUP or GADGETDOWN event.
- */
- BOOL handleGadgetEvent(struct Screen *mysc, struct Window *win, struct Gadget *gad, UWORD code,
- struct Gadget *my_gads[])
- {
- switch (gad->GadgetID)
- {
- case MYGAD_PREVIOUS:
- return(TRUE);
- break;
- case MYGAD_NEXT:
- return(TRUE);
- break;
- case MYGAD_DESTGAD:
- break;
- case MYGAD_DATEGAD:
- break;
- case MYGAD_DIST1:
- break;
- case MYGAD_DISTPOINT:
- break;
- case MYGAD_DIST2:
- break;
- case MYGAD_CYCLEOUTH:
- break;
- case MYGAD_CYCLEOUTM:
- break;
- case MYGAD_CYCLEBACKH:
- break;
- case MYGAD_CYCLEBACKM:
- break;
- case MYGAD_TRAINTICK:
- break;
- case MYGAD_TRAINOUTH:
- break;
- case MYGAD_TRAINOUTM:
- break;
- case MYGAD_TRAINBACKH:
- break;
- case MYGAD_TRAINBACKM:
- break;
- case MYGAD_TOTTIMEH:
- break;
- case MYGAD_TOTTIMEM:
- break;
- }
- return(FALSE);
- }
-
- /*
- ** Function to handle vanilla keys.
- */
- BOOL handleVanillaKey(struct Window *win, UWORD code,
- struct Gadget *my_gads[], int index, int& direction)
- {
- switch (code)
- {
- case ',':
- direction = -1;
- return(TRUE);
- break;
- case '.':
- direction = 1;
- return(TRUE);
- break;
- case 'd':
- case 'D':
- ActivateGadget(my_gads[MYGAD_DESTGAD], win, NULL);
- break;
- case 't':
- case 'T':
- // Change to opposite value and update display
- cycledata[index].train = !cycledata[index].train;
- GT_SetGadgetAttrs(my_gads[MYGAD_TRAINTICK], win, NULL, GTCB_Checked, cycledata[index].train, TAG_END);
- GT_BeginRefresh(win);
- GT_EndRefresh(win, TRUE);
- break;
- }
- return(FALSE);
- }
-
- /*
- ** Here is where all the initialization and creation of GadTools gadgets
- ** take place. This function requires a pointer to a NULL-initialized
- ** gadget list pointer. It returns a pointer to the last created gadget,
- ** which can be checked for success/failure.
- */
- struct Gadget *createAllGadgets(struct Gadget **glistptr, void *vi,
- UWORD topborder, struct Gadget *my_gads[], struct StringInfo *gad_ptr[])
- {
- struct NewGadget ng;
- struct Gadget *gad;
-
- /* All the gadget creation calls accept a pointer to the previous gadget, and
- ** link the new gadget to that gadget's NextGadget field. Also, they exit
- ** gracefully, returning NULL, if any previous gadget was NULL. This limits
- ** the amount of checking for failure that is needed. You only need to check
- ** before you tweak any gadget structure or use any of its fields, and finally
- ** once at the end, before you add the gadgets.
- */
-
- /* The following operation is required of any program that uses GadTools.
- ** It gives the toolkit a place to stuff context data.
- */
- gad = CreateContext(glistptr);
-
- /* Since the NewGadget structure is unmodified by any of the CreateGadget()
- ** calls, we need only change those fields which are different.
- */
-
- ng.ng_LeftEdge = 40;
- ng.ng_TopEdge = 10+topborder;
- ng.ng_Width = 20;
- ng.ng_Height = 10;
- ng.ng_GadgetText = "<";
- ng.ng_TextAttr = &Topaz80;
- ng.ng_VisualInfo = vi;
- ng.ng_GadgetID = MYGAD_PREVIOUS;
- ng.ng_Flags = NG_HIGHLABEL;
- my_gads[MYGAD_PREVIOUS] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
- TAG_END);
-
- ng.ng_LeftEdge = 70;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_PREVTEXT;
- my_gads[MYGAD_PREVTEXT] = gad = CreateGadget(TEXT_KIND, gad, &ng,
- GTTX_Text, "Previous record",
- TAG_END);
-
- ng.ng_LeftEdge = 215;
- ng.ng_Width = 50;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_RECCOUNT;
- my_gads[MYGAD_RECCOUNT] = gad = CreateGadget(NUMBER_KIND, gad, &ng,
- GTNM_Number, 1,
- GTNM_Border, TRUE,
- GTNM_Justification, GTJ_LEFT,
- TAG_END);
-
- ng.ng_LeftEdge = 290;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_NEXTTEXT;
- my_gads[MYGAD_NEXTTEXT] = gad = CreateGadget(TEXT_KIND, gad, &ng,
- GTTX_Text, "Next record",
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 390;
- ng.ng_Width = 20;
- ng.ng_Height = 10;
- ng.ng_GadgetText = ">";
- ng.ng_GadgetID = MYGAD_NEXT;
- my_gads[MYGAD_NEXT] = gad = CreateGadget(BUTTON_KIND, gad, &ng,
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 120;
- ng.ng_Width = 150;
- ng.ng_Height = 12;
- ng.ng_GadgetText = "_Destination:";
- ng.ng_GadgetID = MYGAD_DESTGAD;
- my_gads[MYGAD_DESTGAD] = gad = CreateGadget(STRING_KIND, gad, &ng,
- GTST_String, "",
- GTST_MaxChars, 100,
- GT_Underscore, '_',
- TAG_END);
- gad_ptr[0] = (struct StringInfo *) gad->SpecialInfo;
-
- ng.ng_LeftEdge += 210;
- ng.ng_Width = 90;
- ng.ng_GadgetText = "Date:";
- ng.ng_GadgetID = MYGAD_DATEGAD;
- my_gads[MYGAD_DATEGAD] = gad = CreateGadget(STRING_KIND, gad, &ng,
- GTST_String, "",
- GTST_MaxChars, 8,
- GT_Underscore, '_',
- TAG_END);
- gad_ptr[1] = (struct StringInfo *) gad->SpecialInfo;
-
- ng.ng_LeftEdge = 144;
- ng.ng_Width = 60;
- ng.ng_TopEdge += 20;
- ng.ng_GadgetText = "Cycle Distance:";
- ng.ng_GadgetID = MYGAD_DIST1;
- my_gads[MYGAD_DIST1] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 4,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_Width = 10;
- ng.ng_LeftEdge = 204;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_DISTPOINT;
- my_gads[MYGAD_DISTPOINT] = gad = CreateGadget(TEXT_KIND, gad, &ng,
- GTTX_Text, ".",
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 214;
- ng.ng_Width = 60;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_DIST2;
- my_gads[MYGAD_DIST2] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 4,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 144;
- ng.ng_GadgetText = "Cycle Out Time:";
- ng.ng_GadgetID = MYGAD_CYCLEOUTH;
- my_gads[MYGAD_CYCLEOUTH] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 3,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 214;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_CYCLEOUTM;
- my_gads[MYGAD_CYCLEOUTM] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 2,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 152;
- ng.ng_GadgetText = "Cycle Back Time:";
- ng.ng_GadgetID = MYGAD_CYCLEBACKH;
- my_gads[MYGAD_CYCLEBACKH] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 3,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 222;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_CYCLEBACKM;
- my_gads[MYGAD_CYCLEBACKM] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 2,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 72;
- ng.ng_GadgetText = "_Train?";
- ng.ng_GadgetID = MYGAD_TRAINTICK;
- my_gads[MYGAD_TRAINTICK] = gad = CreateGadget(CHECKBOX_KIND, gad, &ng,
- GTCB_Checked, FALSE,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 190;
- ng.ng_GadgetText = "Out Time:";
- ng.ng_GadgetID = MYGAD_TRAINOUTH;
- my_gads[MYGAD_TRAINOUTH] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 3,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 260;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_TRAINOUTM;
- my_gads[MYGAD_TRAINOUTM] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 2,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 198;
- ng.ng_GadgetText = "Back Time:";
- ng.ng_GadgetID = MYGAD_TRAINBACKH;
- my_gads[MYGAD_TRAINBACKH] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 3,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 268;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_TRAINBACKM;
- my_gads[MYGAD_TRAINBACKM] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 2,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_TopEdge += 20;
- ng.ng_LeftEdge = 112;
- ng.ng_GadgetText = "Total Time:";
- ng.ng_GadgetID = MYGAD_TOTTIMEH;
- my_gads[MYGAD_TOTTIMEH] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 3,
- GT_Underscore, '_',
- TAG_END);
-
- ng.ng_LeftEdge = 180;
- ng.ng_GadgetText = "";
- ng.ng_GadgetID = MYGAD_TOTTIMEM;
- my_gads[MYGAD_TOTTIMEM] = gad = CreateGadget(INTEGER_KIND, gad, &ng,
- GTIN_Number, 0,
- GTIN_MaxChars, 2,
- GT_Underscore, '_',
- TAG_END);
-
- return(gad);
- }
-
-